using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Web.Security;
using System.Data.Entity;
using DomainModel.Concrete;
using DomainModel.Entities;

namespace WebUI.Controllers
{

public class RentInRentalPolicyController : Controller
{
SqlRentInRentalPolicyRepository _rentInRentalPolicyRepository;
 #region PrivateFunctions
private ActionResult HandleMyError(Exception ex, string actionName)
                        {
                            var modelErr = new HandleErrorInfo(ex,  "RentInRentalPolicyController" , actionName);
                            return View("Error", modelErr);
                        }
#endregion
public RentInRentalPolicyController() { _rentInRentalPolicyRepository = new SqlRentInRentalPolicyRepository(); }
#region PublicActions
        public ActionResult Index() 
        { 
             try
                {                 
                    return View(_rentInRentalPolicyRepository.GetAll()); 
                }
              catch (Exception ex) 
                { 
                    return HandleMyError(ex, "CreateAction"); 
                }
            
        }
        
        public ActionResult Details(int id) 
        {  
            try
                {                 
                  return View(_rentInRentalPolicyRepository.GetById(id)); 
                }
              catch (Exception ex) 
                { 
                    return HandleMyError(ex, "CreateAction"); 
                }            
        }
        
        public ActionResult Create() 
        { 
            try
                {                 
                  return View(); 
                }
              catch (Exception ex) 
                { 
                    return HandleMyError(ex, "CreateAction"); 
                }    
            
        }
        
        [HttpPost]
        public ActionResult Create(RentInRentalPolicy rentinrentalpolicy, FormCollection collection)
        {
            if (ModelState.IsValid)
            {  
                try
                {                 
                    _rentInRentalPolicyRepository.Insert(rentinrentalpolicy);
                    return RedirectToAction("Index"); 
                }
                catch (Exception ex) 
                { 
                    return HandleMyError(ex, "CreateAction"); 
                }
            }
            else
            {
                return RedirectToAction("Index");
            }
        }

        public ActionResult Edit(int id)
        { 
            return View(_rentInRentalPolicyRepository.GetById(id));
        }

        [HttpPost]
        public ActionResult Edit(RentInRentalPolicy rentinrentalpolicy, int id, FormCollection collection)
        {
           if (ModelState.IsValid)
            {             
                try
                {        
                
                    _rentInRentalPolicyRepository.Update(rentinrentalpolicy);
                    return RedirectToAction("Index");
                }
                catch (Exception ex)
                {
                    return HandleMyError(ex, "EditAction");
                }
            }
            else
            {
                return RedirectToAction("Index");
            }
        }

        public ActionResult Delete(int id)
        { 
            return View(); 
        }

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                _rentInRentalPolicyRepository.Delete(_rentInRentalPolicyRepository.GetById(id));
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                return HandleMyError(ex, "DeleteAction");
            }
        }
        #endregion
}
}
